from selenium.webdriver.common.by import By


class MainFrame(object):
    frame = (By.XPATH, ".//div[@class='execute']")
    btnBackup = (By.XPATH, ".//*[@id='mainmenu-top']//a[@href='#plugins/index']")
    btnRestore = (By.XPATH, ".//*[@id='mainmenu-top']//a[@href='#restore/index']")
    btnReports = (By.XPATH, ".//*[@id='mainmenu-top']//a[@href='#reports/index']")
    btnOptions = (By.XPATH, ".//li[@id='options']/a")
    btnLSVSetup = (By.XPATH, './/div[@class="speedkick"]/a[@data-url-id="options_speed_vault"]')
    btnScheduleSetup = (By.XPATH, './/*[@class="setup-schedule"]')
    btnManageDevices = (By.XPATH, './/div[@class="more-devices"]/button')
    btnAssignToAccount = (By.ID, "oauth-create-account")
    btnBuyNow = (By.XPATH, './/div[@id="trial-period-container"]//button[@name="cancel"]')
    feedBackLink = (By.XPATH, ".//*[@id='left-page-menu']/*/div[@class='feeedback']/a")
    frameTeamViewer = (By.XPATH, './/div[@id="oauth-frame"]/iframe')
    trialLabel = (By.ID, 'trial-period-container')
    btnRunBackup = (By.XPATH, './/div[@class="right-sidebar"]/div/div/a')
    formLoader = (By.XPATH, './/div[@id="main-container"]/div[@class="loader"]')
    menuMain = (By.XPATH, 'xpath', '//*[@class="mainmenu" and not(@id)]')


class TreeDialog(object):
    treeView = (By.ID, 'folder-tree-container')
    btnOK = (By.XPATH, './/div[@id="folder-selector-dialog"]//button[@name="ok"]')
    btnCancel = (By.XPATH, './/div[@id="folder-selector-dialog"]//button[@name="cancel"]')


class BackupRestoreProgress(object):
    percentLabel = (By.XPATH, ".//div[@class='status-backup-container']//p[@class='title-bottom']/span")
    progressBar = (By.XPATH, ".//div[@class='status-backup-container']")
    backupCompleteMarker = (By.XPATH, ".//span[@class='progressbar-process']")


class Backup(object):
    backupPage = (By.XPATH, ".//*[@id='main-container']/div[@class='inner']")
    backupTree = (By.XPATH, ".//*[@id='file-tree-container']")
    backupListView = (By.XPATH, ".//*[@id='main-container']/div[2]/ul")

    class BackupList(object):
        pluginCheckbox = (By.XPATH, 'div[@class="onoffswitch"]/label')
        pluginLoader = (By.XPATH, './/label[contains(@class, "pluginloader")]')

class Restore(object):
    restorePage = (By.XPATH, ".//*[@id='main-container']/div[@class='inner']/div[@class='restore-container']")
    restoreTreeView = (By.XPATH, ".//*[@id='restore-file-tree-container']")
    sessionComboBox = (By.XPATH, ".//*[@id='restore-session-container']/div[2]/div/div")
    pluginComboBox = (By.XPATH, ".//*[@id='restore-list-files']/div[2]/div/div[1]/div/div/div")
    btnStartRestore = (By.XPATH, ".//button[@id='start-restore-btn']")
    radioBtnRestoreToOriginalLoc = (By.ID, 'original_location')
    radioBtnRestoreToPath = (By.ID, 'spec_location')
    txtRestoreToPath = (By.ID, 'restoreToPath')
    txtSearch = (By.ID, 'restoreSearchQuery')
    searchResultTable = (By.ID, 'restore-search-result-table')
    searchResultList = (By.XPATH, ".//div[@id='restore-list-files']/div/div[@class='search-result-container']")

    class ListSearchResultItem(object):
        labelFilePath = (By.XPATH, ".//div[@class='filepath']/span")
        labelBackupTime = (By.XPATH, ".//div[@class='backuptime']")
        labelFileSize = (By.XPATH, ".//div[@class='filessize']")
        listItem = (By.XPATH, ".//div[contains(@class, 'searchresult-container')]")

class Reports(object):
    reportsPage = (By.XPATH, ".//*[@id='main-container']/div[@class='inner']/div[@class='reportTableHeader']")
    reportsListView = (By.XPATH, './/*[@id="main-container"]/div/div[@role="tablist"]')

class Dialog(object):
    anyDialog = (By.XPATH, "html/body/div[contains(@class ,'ui-dialog')]")
    btnSaveFileTreeDialog = (By.XPATH, ".//*[@id='file-tree-dialog']/div[2]/button[1]")
    btnCancelFileTreeDialog = (By.XPATH, ".//*[@id='file-tree-dialog']/div[2]/button[2]")
    btnSaveOptions = (By.XPATH, './/*[@id="dialog-options"]//button[@name="save"]')
    btnCancelOptions = (By.XPATH, ".//*[@id='dialog-options']/div[2]/button[1]")


class Options(object):
    menuPreferences = (By.CLASS_NAME, 'prefmenu')
    menuItemActive = (By.CLASS_NAME, 'active')

    btnGeneral = (By.CSS_SELECTOR, 'a[data-url-id="options_general"]')
    btnFilter = (By.CSS_SELECTOR, 'a[data-url-id="options_filters"]')
    btnSchedule = (By.XPATH, './/*[@id="dialog-options"]//a[@href="#options/schedule/index"]')
    btnScripts = (By.XPATH, './/*[@id="dialog-options"]//a[@data-url-id="options_scripts"]')
    btnBandwidth = (By.CSS_SELECTOR, 'a[data-url-id="options_bandwidth"]')
    btnLocalSpeedKick = (By.XPATH, './/*[@id="dialog-options"]//a[@data-url-id="options_speed_vault"]')
    btnProxy = (By.CSS_SELECTOR, 'a[data-url-id="options_proxy"]')
    btnAdvanced = (By.CSS_SELECTOR, 'a[data-url-id="options_advanced"]')

    winDialogOptions = (By.ID, 'dialog-options')

    class General(object):
        txtboxMailAddress = (By.ID, 'MailAddress')
        cbMailSendPeriodicity = (By.XPATH, './/div[@class="dropdownContainer"]/div')
        checkboxRemoteConnection = (By.ID, 'EnableRemoteConnection')

    class Filter(object):
        tfFilterName = (By.XPATH, ".//*[@id='filterName']")
        btnAddFilter = (By.ID, 'btn-add-filter')
        btnEditFilter = (By.ID, 'btn-edit-filter')
        btnDeleteFilter = (By.ID, 'btn-delete-filter')
        listBoxFilters = (By.CSS_SELECTOR, 'div[class="dropdownContainer"]')

    class Schedule(object):
        frame = (By.XPATH, ".//div[@class='optionshedule windowLoad']")
        btnAddSchedule = (By.ID, 'add-schedule-btn')
        listViewSchedule = (By.XPATH, ".//*[@id='preferences-container']//ul[@class='schedulemenu']")

        class listScheduleItem(object):
            checkboxEnabled = (By.XPATH, ".//div[@class='onoffswitch']/label")
            labelScheduleName = (By.XPATH, ".//p[@class='schedulemenuheader']")
            btnEditSchedule = (By.XPATH, ".//a[@class='scheduleicon']")

        class EditSchedule(object):
            txtboxScheduleName = (By.ID, "ScheduleName")
            txtboxFireTime = (By.ID, "SchedulefireTime")
            cbPreBackup = (By.XPATH, ".//*[@id='add-scheduler-popup']/div[2]/div/div/form/div[2]/div[1]/div")
            listDaysOfWeek = (By.XPATH, ".//div[@class='settings']/div[2]/div/div")
            listPlugins = (By.XPATH, ".//div[@class='settings']/div[3]/div/div")
            cbPostBackup = (By.XPATH, ".//div[@class='settings']/div[4]/div")
            btnSave = (By.XPATH, ".//div[@id='add-scheduler-popup']//button[@name='save']")
            btnCancel = (By.XPATH, ".//div[@id='add-scheduler-popup']//button[@name='cancel']")
            btnDelete = (By.ID, "delete-schedule-btn")

    class Scripts(object):
        btnAdd = (By.ID, 'add-script-btn')
        btnEdit = (By.ID, 'edit-script-btn')
        btnDelete = (By.ID, 'delete-script-btn')
        listBoxScripts = (By.XPATH, ".//form/div[@class='dropdownContainer']")
        winDialogEdit = (By.XPATH, '//div[starts-with(@class, "ui-dialog ui-widget ui-widget-content")]')

        class EditScript(object):
            winDialogEditScript = (By.ID, 'dialog-scripts-add')
            txtboxScriptName = (By.ID, 'scriptName')
            txtboxUserName = (By.ID, 'scriptUser')
            txtboxPassword = (By.ID, 'scriptPassword')
            txtboxTimeout = (By.ID, 'scriptTimeout')
            checkboxFailOnError = (By.ID, 'failOnError')
            txtboxErrorMessage = (By.ID, 'scriptErrorMessage')
            btnSave = (By.XPATH, '//div[@id="add-script-popup"]//button[@name="save"]')
            btnCancel = (By.XPATH, '//div[@id="add-script-popup"]//button[@name="cancel"]')

    class Bandwidth(object):
        frame = (By.CLASS_NAME, 'optionbandwidth windowLoad')
        checkboxLimit = (By.ID, 'BandwithThrottlingLimited')
        checkboxWeekendLimit = (By.ID, 'BandwithnoLimitationOnSatSun')
        txtTurnOnTime = (By.ID, 'BandwithTurnon')
        txtTurnOffTime = (By.ID, 'BandwithTurnoff')
        txtUploadSpeed = (By.ID, 'BandwithThrottlingUploadValue')
        txtDownloadSpeed = (By.ID, 'BandwithThrottlingDownloadValue')

    class LocalSpeedKick(object):
        frame = (By.XPATH, '//form[@data-form-type="local-speedkick"]')
        checkboxBackupCacheEnabled = (By.ID, 'BackupCacheEnabled')
        comboBoxDriveType = (By.XPATH, '//form[@data-form-type="local-speedkick"]/div[position()=2]')
        txtBoxCacheLocation = (By.ID, 'BackupCacheLocation')
        txtBoxUser = (By.ID, 'BackupCacheUser')
        txtBoxPassword = (By.ID, 'BackupCachePassword')

        # class LocationDialog(object):
        #     treeViewLocation = (By.ID, 'folder-tree-container')
        #     btnOK = (By.CSS_SELECTOR, 'div[id="folder-selector-dialog"] div button[name="ok"]')
        #     btnCancel = (By.CSS_SELECTOR, 'div[id="folder-selector-dialog"] div button[name="cancel"]')

    class Advanced(object):
        cbLanguage = (By.XPATH, "//div[@class='dropdownContainer']/div")
        txtBoxTemp = (By.ID, 'TempDir')

        # class TempDirDialog(object):
        #     treeViewTempDir = (By.ID, 'folder-tree-container')
        #     btnOK = (By.CSS_SELECTOR, 'div[id="folder-selector-dialog"] div button[name="ok"]')
        #     btnCancel = (By.CSS_SELECTOR, 'div[id="folder-selector-dialog"] div button[name="cancel"]')